<?php
	$location_id = $params[0];
	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$title			= strip_tags($_POST['title']);
		$telephone		= strip_tags($_POST['telephone']);
		$lat			= strip_tags($_POST['lat']);
		$lng			= strip_tags($_POST['lng']);
		$address			= $_POST['address'];
		$status			= $_POST['status']=='publish' ? '1': '0';
 
		$upload_fieldname	= 'thumb';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/location/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_basename = basename($upload_fullpath);
			$sql_uploads = " , `thumb` = '$upload_basename'";
		}

		$sql = "UPDATE `tbl_locations` SET `title` = '$title', `telephone` = '$telephone'  ,  `address` = '$address' ,`lat` = '$lat'  , `lng` = '$lng'  $sql_uploads  , `status` = '$status' WHERE  `location_id` = '$location_id' LIMIT 1;";
		mysql_query($sql);
	 	redirect('../');
		exit;
	}

	$sql = "SELECT * FROM `tbl_locations` WHERE `location_id` = '$location_id' LIMIT 1";
	$query = mysql_query($sql);
	while($result = mysql_fetch_assoc($query)) {
		$title			= $result['title'];
		$telephone		= $result['telephone'];
		$lat			= $result['lat'];
		$lng			= $result['lng'];
		$address		= $result['address'];
		$thumbHTML		= $result['thumb'] ? "<img src=\"/thumb/195/zc/contents/location/{$result['thumb']}\" /><br />": "";
	}
	mysql_free_result($query);
 
	include 'ckeditor/ckeditor.php';
	include 'ckeditor/ckfinder/ckfinder.php';
	
	$ckeditor = new CKEditor();
	$ckeditor->returnOutput			= true;
	$ckeditor->basePath				= '/backend/ckeditor/';
	$ckeditor->config['toolbar']	= 'Basic';
	$ckeditor->config['height']		= '100';
	$ckeditor->config['width']		= '500';

	CKFinder::SetupCKEditor($ckeditor, '/backend/ckeditor/ckfinder/');
	$addressHTML = $ckeditor->editor('address', $address);
?>